#include <mylib/device/grayscale.h>

// 直接并口读取数据
void grascale_get_data(grascale_t* grascale)
{
    // 读取数据
    for (int32_t i = 0; i < GRAYSCALE_SIZE; i++) {
#if PLATFORM_STM32
        if (HAL_GPIO_ReadPin(grascale->single_grayscales[i].port,
                             grascale->single_grayscales[i].pin) ==
            grascale->single_grayscales[i].valid) {
            grascale->single_grayscales[i].state = true;
        }
#elif PLATFORM_MSPM0
#    error current platform not support
#endif
        else {
            grascale->single_grayscales[i].state = false;
        }
    }
}

// 清空状态
void grayscale_clear_state(grascale_t* grascale)
{
    for (int32_t i = 0; i < GRAYSCALE_SIZE; i++) {
        grascale->single_grayscales[i].state = false;
    }
}
